<template>
  <view class="login">
    <view class="uni-form-item uni-column">
      <button @click="checkLockScreenPassword">点击输入锁屏密码</button>
    </view>
  </view>
</template>

<script setup lang="ts">
import { onMounted, ref } from 'vue'
//
let failCount = 0


onMounted(() => {
  console.log('login onMounted')
  startSoterAuthentication()
})


// 在需要验证锁屏密码的地方调用此函数
function checkLockScreenPassword() {
  uni.navigateTo({
    url: '/pages/index/index',
  })

}

function startSoterAuthentication() {
  uni.startSoterAuthentication({
    requestAuthModes: ['fingerPrint'],
    challenge: '111xx',
    authContent: '使用指纹解锁',
    success(res) {
      console.log(res)
      if (res.errCode === 0) {
        console.log('login success')
        // 跳转到index
        //在起始页面跳转到test.vue页面并传递参数
        uni.navigateTo({
          url: '/pages/index/index',
        })

      } else {
        console.log('login error')
        // 递归
        loginFail()
      }
    },
    fail(err) {
      console.log(err)
      // 递归
      loginFail()
    },
    complete(res) {
      // console.log(res)
    },
  })
}

function loginFail() {

  if (++failCount > 5) {
    return

  }
  setTimeout(() => startSoterAuthentication(), 500)

}
</script>

<style lang="scss">
//
</style>
